<div class="pagetitle">
	<h1>Check Coupon tại <?php echo $restaurant;?></h1>
</div>
<div class="maincontent">
    <?php if(validation_errors()):?>
        <div class="alert alert-error" style="margin: 10px 10px 10px 40px;">
          <button data-dismiss="alert" class="close" type="button">×</button>
          <?php echo validation_errors(); ?>
        </div>
    <?php endif;?>
    
    <div class="contentinner content-dashboard">    
    <?php if(@$success == 200):?>
    <p>
        <label></label>
        <span class="field">
            <p>Bạn vừa cập nhật sử dụng coupon thành công</p>
        </span>
        <button class="btn btn-rounded" type="button" onclick="window.location='<?php echo $baseurl.'manage/userecoupon/add-user-ecoupon'?>'"> <i class="iconfa-ok"></i> <span class="search_btn">&nbsp;Thêm mới</span></button>
        <button class="btn btn-rounded export_1_code" type="button"> <i class="iconfa-ok"></i> <span style="font-weight: bold;color: blue;" class="search_btn">&nbsp;Xuất báo cáo</span></button>
		<input type="hidden" class="code_ecoupon" value="<?php echo $code_coupon;?>"/>
    </p>
    <?php elseif(@$success == 201):?>
    <p>
        <label></label>
        <span class="field">
            <p>Bạn cập nhật thất bại, vui lòng kiểm tra lại</p>
        </span>
        <button class="btn btn-rounded" type="button" onclick="window.location='<?php echo $baseurl.'manage/userecoupon/add-user-ecoupon'?>'"> <i class="iconfa-ok"></i> <span class="search_btn">&nbsp;Làm lại</span></button>
        <button class="btn btn-rounded" type="button" onclick="window.location='<?php echo $baseurl.'manage/userecoupon/user-ecoupon'?>'"> <i class="icon-arrow-right"></i> &nbsp; Hủy bỏ</button>
    </p>
    <?php else:?>
        <p id="label_form" style="margin: 35px 5px 10px 0px;font-size: 18px;">
            <label class="hr">Tìm kiếm mã E-coupon</label>
        </p>
        <div id="searchCoupon" class="stdform">
            <p>
            	<label>Nhập mã E-coupon</label>
                <span class="field"><input type="text" value="" id="code_coupon" name="code_coupon" class="input-xxlarge" placeholder="Nhập mã E-coupon" /></span>
            </p>
            <p>
                <label></label>
                <button class="btn btn-rounded btn-search-click" type="button"> <i class="iconfa-ok"></i> <span class="search_btn">&nbsp;Tìm kiếm</span></button>
                <button class="btn btn-rounded" type="button" onclick="window.location='<?php echo $baseurl.'manage/userecoupon/user-ecoupon'?>'"> <i class="icon-arrow-right"></i> &nbsp; Hủy bỏ</button>
            </p>
        </div>
        <?php $attr = array('class' => 'stdform'); echo form_open('', $attr)?>
            <div id="form_id">
                
            </div>
        </form>
    <?php endif;?>
    
    <br /><br /><h3>Các coupon đang áp dụng tại <?php echo $restaurant;?></h3>
    <?php foreach($listCouponActive AS $key => $value):?>
        <p>&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;<?php echo $value->title?></p>
    <?php endforeach;?>
    </div>
</div>
<div id="hideReport" style="display: none;"></div>
<style>
.hr{
    margin: 10px 0px;padding-bottom: 10px !important;width: 98% !important;float: left;text-align: left !important;font-size: 19px;border-bottom: 1px solid #fff;border-bottom: 1px solid #ececef;box-shadow: 0px 1px 0px #FFF;
}
</style>
<script>

$(function()
{
    $(".btn-search-click").click(function()
    {
        var code_coupon = $("#code_coupon").val();
        if(code_coupon == null || code_coupon == '' || code_coupon == undefined)
        {
            jAlert('<center><b>Vui lòng nhập vào mã coupon</b></center>', 'Thông báo', function()
            {
                return false;
            });
            return false;
        }
        $(".search_btn").html('Đang tìm ...');
        $.ajax({
           type: 'get',
           url: '<?php echo $baseurl.'manage/userecoupon/search-user-ecoupon'?>',
           data: ({code: code_coupon}),
           success: function(data)
           {
                if(data == '202' || data == '404' )
                {
                    $(".search_btn").html('Tìm kiếm');
                    jAlert('<center><b>Không tìm thấy mã coupon bạn vừa nhập</b></center>', 'Thông báo', function()
                    {
                        return false;
                    });
                    return false;
                }else{
                    //$("#label_form").remove();
                    $("#form_id").html(data);
                    $("#searchCoupon").html('');
                    //$(".btn-search-click").addClass('addsuccess');
                }
                
           },
           error: function()
           {
                $(".search_btn").html('Tìm kiếm');
                jAlert('Không tìm thấy mã coupon bạn vừa nhập, vui lòng thử lại.', 'Thông báo', function()
                {
                    return false;
                });
                return false;
           }
        });
    });
});
</script>
<script type="text/javascript">
    $(document).ready(function(){
        $('.export_1_code').on('click', function(){
			var code_coupon = $('.code_ecoupon').val();
            $.ajax({
               type: "GET",
               url: baseUrl+'manage/userecoupon/export-1-ecoupon',
               data: ({code_coupon: code_coupon }),
               beforeSend: function(){
                    showPreload();
               },
               success: function(n){
                    $('#hideReport').html(n);
                    exportToExcel();
               }  
            });
        });
    });
</script>